// 主界面

#include "head.h"
#include "chess_board.h"
#include "game.h"

class UIMain : public UI::Scene
{
public:
	UIMain()
	{
		_spr = UI::Sprite::Create(
			g_factory->CreateSprite("bg"),
			UI::Sprite::AutoSize::PANEL, 
			UI::Sprite::FillMode::RATIO_OUT);
		GetPanelRoot()->SetOrderMode(UI::Panel::OrderMode::FORCE);
		GetPanelRoot()->SetOrder(ORDER_BG);
		GetPanelRoot()->Add(_spr);

		// 
		_panelBoard = CreatePanel("board");
		_panelBoard->SetPosScale({ 0.1f, 0.5f });

		// 
		_panelMenu = CreatePanel("menu");
		_panelMenu->SetPosScale({ 0.1f, 0.5f });
		_panelMenu->SetPosPixel(棋盘偏移 + Position{ 棋盘像素大小[0] + 260.0f , 0 });
		Locator::SL loc;
		loc._layout = Layout::Y;
		loc._dt = { 0, 80 };
		_panelMenu->SetLocator(loc);
		{
			auto btn = g_Res->GetButtonWood();
			btn->SetString(lang("菜单.新的一局"));
			_panelMenu->Add(btn);
		}
		{
			auto btn = g_Res->GetButtonWood();
			btn->SetString(lang("菜单.残局定式练习"));
			_panelMenu->Add(btn);
		} 
		{
			auto btn = g_Res->GetButtonWood();
			btn->SetString(lang("菜单.红黑互换"));
			_panelMenu->Add(btn);
		}
		{
			auto btn = g_Res->GetButtonWood();
			btn->SetString(lang("菜单.建立服务器"));
			_panelMenu->Add(btn);
		}

		//
		_panelMsg = CreatePanel("msg");
		_panelMsg->SetPosScale({ 0.1f, 0.5f });
		_panelMsg->SetPosPixel(棋盘偏移 + Position{ 棋盘像素大小[0] + 490.0f , 0 });
		UI::EditBox* edt = g_Res->GetEditBox();
		_panelMsg->Add(edt);


		_ChessBoard.SetParent(_panelBoard->GetCoorRef());
	}
	void Update()
	{
		size_t idx = _panelMenu->GetClickIndex();
		if (idx == 0)
			_ChessBoard.New();
	}
	void Render()
	{
		_ChessBoard.Render();
	}
private:
	UI::Sprite* _spr;
	ChessBoard _ChessBoard;
	UI::Panel* _panelBoard;
	UI::Panel* _panelMenu;
	UI::Panel* _panelMsg;
};